#ifndef FOREGROUND_H_6ZEDEW1P
#define FOREGROUND_H_6ZEDEW1P

/*
 *  scenery.h
 *  
 *
 *  Created by Jason Hsu, Jian Wei Gan, and Weiping Zhang on 11/4/09.
 *  Copyright 2009. All rights reserved.
 *
 */

#include "texture.h"
#include <vector>
#include "imageprocessor.h"
#include "sunflower.h"
#include "rain.h"
#include "weather/weatherparser.h"
#include "util/vec3f.h"
#include "util/color4f.h"
#include "terrain.h"

class Foreground
{
private:
    weather_t *myWeather;
    ImageProcessor *myImageProcessor;

    list<Cloud *>* myClouds;

	list<Sunflower*>* mySunflowerList;
	GLint myNumSunflowers;

	
public:
	Foreground(weather_t *weather, Terrain* terrain)
	{
        myWeather = weather;
		//############################# Clouds
		myClouds = new list<Cloud *>();
		
		myNumSunflowers = 18;
		mySunflowerList = new list<Sunflower*> ();
		for(GLint k = 0; k<myNumSunflowers; k++)
		{
			GLfloat x, z;
			if(k < 6)
			{
				x = 15.0f + k;
				z = 48.0f + randFloatRange(-1.0f, 1.0f);
			}
			else if(k < 12)
			{
				x = 25.0f + k;
				z = 38.0f + randFloatRange(-1.0f, 1.0f);
			}
			else {
				x = 35.0f + k;
				z = 35.0f + randFloatRange(-1.0f, 1.0f);
			}

			
			Sunflower* sf = new Sunflower(weather);
			sf->setPosition((x-29.0f)*(160.0f/60.0f), terrain->getHeight(x, z), z-59.0f);
            sf->scale();
			
			mySunflowerList->push_back(sf);
		}
		
		myImageProcessor = new ImageProcessor(myClouds, mySunflowerList, myWeather);
	}
	
	~Foreground()
	{
		for(GLint k = 0; k<myNumSunflowers; k++)
		{
			mySunflowerList->pop_back();
		}
		delete mySunflowerList;
		delete myImageProcessor;
        delete myClouds;
	}
	
	void facePoint(GLfloat xToFace) 
	{
	    
	}
	
	void draw()
	{
        list<Cloud*>::iterator it;
		for (it=myClouds->begin(); it != myClouds->end(); it++) {
			(*it)->draw();
		}
        
		list<Sunflower*>::iterator iter;
		for(iter = mySunflowerList->begin(); iter != mySunflowerList->end(); iter++)
		{
			(*iter)->draw();
		}
	}
	
	void update(GLfloat elapsedTime)
	{
        myImageProcessor->update(elapsedTime);
		
		list<Cloud *>::iterator it;
		for (it=myClouds->begin(); it != myClouds->end(); it++) {
			(*it)->update();
		}
		
		list<Sunflower*>::iterator iter;
		for(iter = mySunflowerList->begin(); iter != mySunflowerList->end(); iter++)
		{
			(*iter)->update();
		}
	}
};

#endif /* end of include guard: FOREGROUND_H_6ZEDEW1P */
